package leetcode_数组.统计数组中的元素;

import java.util.Arrays;

// H 指数
public class _274 {
    public static void main(String[] args) {
        int[] ints = {100};
        System.out.println(hIndex(ints));
    }

    public static int hIndex(int[] citations) {
        if (citations.length == 0) {
            return 0;
        }
        if (citations.length == 1) {
            return citations[0] == 0 ? 0 : 1;
        }
        Arrays.sort(citations);
        for (int i = citations.length - 1; i >= 0; i--) {
            int count = 0;
            for (int citation : citations) {
                if (citation >= citations[i]) {
                    count += 1;
                }
            }
            if (count == citations[i]) {
                return count;
            }
        }
        return 0;
    }

}
